const express = require('express')
const morgan=require('morgan')
const cors=require('cors')
const router=require('./router')
const errorHandler = require('./middleware/error-handler')
//导入数据持久层，自动连接数据库
require('./model')

const app=express()

app.use(morgan('dev'))
app.use(express.json())
// app.use(express.urlencoded())
app.use(cors())

app.use('/api',router)
app.use(errorHandler())
const PORT=process.env.PORT||8081
app.listen(PORT,()=>{
    console.log(`Server running at http://localhost:${PORT}`)
})